const { Keypair } = require("@solana/web3.js");

const config = require('./config');
const bip39 = require('bip39');
const ed25519 = require('ed25519-hd-key');

const getSeedFromMne = async () => {
    return await bip39.mnemonicToSeed(config.mnemonic);
}

const user1 = async ()=>{
    const seed = await getSeedFromMne();
    const user1Seed = ed25519.derivePath(config.account1.path,seed.toString('hex')).key;
    const user1_keypair = Keypair.fromSeed(user1Seed);
    const user1_addr = user1_keypair.publicKey.toBase58();
    const user1_privKey = user1_keypair.secretKey;

    console.log('user1_addr: ', user1_addr);
    console.log('user1_privKey: ', user1_privKey);
    return user1_keypair;

}
const user2 = async ()=> {
    const seed = await getSeedFromMne();
    const user2Seed = ed25519.derivePath(config.account2.path,seed.toString('hex')).key;
    const user2_keypair = Keypair.fromSeed(user2Seed);
    const user2_addr = user2_keypair.publicKey.toBase58();
    const user2_privKey = user2_keypair.secretKey;

    console.log('user2_addr: ', user2_addr);
    console.log('user2_privKey: ', user2_privKey);
    return user2_keypair;
}

const user3 = async () => {
    const seed = await getSeedFromMne();
    const user2Seed = ed25519.derivePath(config.account3.path,seed.toString('hex')).key;
    const user2_keypair = Keypair.fromSeed(user2Seed);
    const user2_addr = user2_keypair.publicKey.toBase58();
    const user2_privKey = user2_keypair.secretKey;

    console.log('user3_addr: ', user2_addr);
    console.log('user3_privKey: ', user2_privKey);
    return user2_keypair;
}
//usr1();
//user2();

module.exports = {
    user1,user2, user3
}